package com.crazybird.vote.view;

import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.util.Map;

/**
 * @author luogm
 * @Type RestJacksonJsonView
 * @Desc json映身java
 * @date 2016-08-03
 * @Version V1.0
 */
public class RestJacksonJsonView extends MappingJackson2JsonView {

    /**
     * 重写方法,去掉json的键值对,只保
     */
    @Override
    protected Object filterModel(Map<String, Object> model) {
        Object resultObject = null;
        Map<?, ?> result = (Map<?, ?>) super.filterModel(model);
        if (result.size() == 1) {
            resultObject = result.values().iterator().next();
        } else {
            resultObject = result;
        }
        return resultObject;
    }
}
